package com.hutianao.gqgl.systemSetting.service.impl;

import com.hutianao.gqgl.mybatis.entity.PtRoleEntity;
import com.hutianao.gqgl.mybatis.entity.PtSystemSetting;
import com.hutianao.gqgl.mybatis.flexigrid.PaddingEntity;
import com.hutianao.gqgl.mybatis.flexigrid.PadingRstType;
import com.hutianao.gqgl.organ.entity.SearchResultEntity;
import com.hutianao.gqgl.systemSetting.entity.SearchsystemSettingEntity;
import com.hutianao.gqgl.systemSetting.respository.SystemSettingDao;
import com.hutianao.gqgl.systemSetting.service.SystemSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemSettingServiceImpl implements SystemSettingService {

    @Autowired
    private SystemSettingDao systemSettingDao;

    @Override
    public PadingRstType<PtSystemSetting> querySystemInfoListByPage(SearchsystemSettingEntity search, PaddingEntity padding) {
        padding.deal(PtRoleEntity.class);
        PadingRstType<PtSystemSetting> padingRstType = new PadingRstType<>();
        padingRstType.setPage(padding.getPage());

        List<PtSystemSetting> list = systemSettingDao.listSysSettingByName(search,padding);
        Integer total = systemSettingDao.countSysSettingByName(search);


        padingRstType.setRawRecords(list);
        padingRstType.setTotal(total);
        padingRstType.putItems();

        return padingRstType;
    }


    @Override
    public String addSystemInfoInfo(PtSystemSetting ptSystemSetting) {
        ptSystemSetting.setCfgId(System.currentTimeMillis()/1000);
        systemSettingDao.addSystemInfoInfo(ptSystemSetting);
        return "add.systemInfo.success";
    }

    @Override
    public String updateSystemInfoInfo(PtSystemSetting ptSystemSetting) {
        systemSettingDao.updateSystemInfoInfo(ptSystemSetting);
        return "update.systemInfo.success";
    }

    @Override
    public String deleteSystemById(String systemUuidArray) {

        String[] systemUuids=systemUuidArray.split(",");

        int count = systemSettingDao.deleteSystemById(systemUuids);
        return "delete.systemInfo.success";
    }
}
